//
//  BaseViewController.swift
//  FirstSwiftProduct
//
//  Created by 知合金服-Mini on 2017/10/31.
//  Copyright © 2017年 范泽华. All rights reserved.
//

import UIKit

protocol changeSizeDelegate : class{
    func chnageSize() ;
    
}

class BaseViewController: UIViewController {
    
    
//    weak var delegate:changeSizeDelegate?
    
    let leftWidth :CGFloat = 200
    
    
    var backView :UIView!
    var titleLabel = UILabel()
    var leftView : UIView!
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        self.automaticallyAdjustsScrollViewInsets = false
        self.view.backgroundColor = UIColor.white
      
        //        self.navigationController?.navigationBar.isHidden = false
        //        navigationController?.navigationBar.isHidden = false
        setUpNav()
    }
    
    func setUpNav() -> Void {
        
        let leftNav = LeftNavView.init(frame: CGRect(x: 0, y: 0, width: leftWidth, height: SCRENN_HEIGHT))
        
        view.addSubview(leftNav)
        
        backView = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCRENN_HEIGHT))
        view.addSubview(backView)
        
        let topView = UIView.init(frame: CGRect(x: 0, y: 0, width: Int(SCREEN_WIDTH), height: kStatus_Navigation_height))
        topView.backgroundColor = kBlackTextColor
        
        
        let backBtn = UIButton.init(type: UIButtonType.custom)
        backBtn.frame = CGRect(x: 20 * scaleWidth, y: 20, width: 38, height: 38)
        backBtn.layer.cornerRadius = 19
        backBtn.layer.masksToBounds = true
        backBtn.setImage(UIImage.init(named: "father"), for: UIControlState.normal)
        backBtn.addTarget(self, action: #selector(backAction), for: UIControlEvents.touchUpInside)
        topView.addSubview(backBtn)
        backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignment.left

        titleLabel = UILabel.init(frame: CGRect(x: (SCREEN_WIDTH - 30)/8, y: backBtn.center.y - 15 , width: SCREEN_WIDTH - (SCREEN_WIDTH - 30)/8*2, height: 30))
        titleLabel.textAlignment = NSTextAlignment.center
        titleLabel.textColor = kBgWhiteColor
//        titleLabel.font = UIFont.systemFont(ofSize: 18)
        titleLabel.font = UIFont.boldSystemFont(ofSize: 18)
        topView.addSubview(titleLabel)

        backView.addSubview(topView)
    
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.backView.x = 0
        self.tabBarController?.tabBar.x = 0
        
        UIApplication.shared.statusBarStyle = .lightContent
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.backView.x = 0
        self.tabBarController?.tabBar.x = 0
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        let content = backView.x
        if content == 100 {
            UIView.animate(withDuration: 1.0) {
                self.backView.x = 0
                self.tabBarController?.tabBar.x = 0
            }
        }
    }
    
    
    func backAction() -> Void {
//        self.navigationController?.popViewController(animated: true)
//        delegate?.chnageSize()
        
        let content = backView.x
        if content < 100 {
            UIView.animate(withDuration: 1.0) {
                self.backView.x = self.leftWidth
                self.tabBarController?.tabBar.x = self.leftWidth
            }
        }else{
            UIView.animate(withDuration: 1.0) {
                self.backView.x = 0
                self.tabBarController?.tabBar.x = 0
            }
        }

//        leftView.frame = CGRect(x: 0, y: 0, width: 100, height: SCRENN_HEIGHT)
    }

//    override var preferredStatusBarStyle: UIStatusBarStyle
//        {
////        return .lightContent
//         return .default
//    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
